package com.uwo.house.service.serviceImpl;

import com.uwo.house.beans.request.InfoAboutReq;
import com.uwo.house.beans.request.SupplierPartnerReq;
import com.uwo.house.beans.response.*;
import com.uwo.house.dao.AdministratorDao;
import com.uwo.house.service.IAdministratorService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.List;

/**
 * Created by cyn1c on 2017/8/19.
 */
@Service
public class AdministratorService implements IAdministratorService {
    @Autowired
    private AdministratorDao administratorDao;

    @Transactional
    public int addInfo(InfoAboutReq infoAboutReq) {
        int result2 = 2;
        try {
             administratorDao.deleteAbout();
        }catch (Exception e){
            result2 = 1;
        }
        int result1 = administratorDao.addInfo(infoAboutReq);
        if (result2 != 1 && result1 == 1) {
            return 1;
        }
        return 2;
    }

    public InfoAboutResp getCompanyAbout() {
        return administratorDao.getCompanyAbout().get(0);
    }

    public int addServiceFlow(String flowPic){
        administratorDao.deleteServiceFlow();
        return administratorDao.addServiceFlow(flowPic);
    }

    public String getServiceFlow(){
        return administratorDao.getServiceFlow();
    }
    public int addDeliverCompany(String deliverCompany){
        return administratorDao.addDeliverCompany(deliverCompany);
    }

    public int deleteDeliverCompany(int id){
        return administratorDao.deleteDeliverCompany(id);
    }

    public List<DeliverCompanyResp> getDeliverCompany(String deliverCompany){
        return administratorDao.getDeliverCompany(deliverCompany);
    }

    public int addMoneySet(BigDecimal deposit, BigDecimal reward){
        int result2 = 2;
        try {
            administratorDao.deleteMoneySet();
        }catch (Exception e){
            result2 = 1;
        }
        int result1 = administratorDao.addMoneySet(deposit,reward);
        if (result2 != 1 && result1 == 1) {
            return 1;
        }
        return 2;
    }

    public int addSupplierPartner(SupplierPartnerReq supplierPartnerReq) {
        return administratorDao.addSupplierPartner(supplierPartnerReq);
    }

    public int deleteSupplierPartner(int id){
        return administratorDao.deleteSupplierPartner(id);
    }

    public  List<SupplierPartnerResp> getSupplierPartnerList(){
        return administratorDao.getSupplierPartnerList();
    }

    public int modifySupplierPartner(SupplierPartnerReq supplierPartnerReq){
        return administratorDao.modifySupplierPartner(supplierPartnerReq);
    }

    public int getRewardMoney(){
        return administratorDao.getRewardMoney();
    }

    public BigDecimal getDepositMoney(){
        return administratorDao.getDepositMoney();
    }

    public List<MaterialOrderResp> getMaterialOrderList(String orderNo, String supplierNo, String preOrderStatus, String deliverGoodsStatus) {
        return administratorDao.getMaterialOrderList(orderNo, supplierNo, preOrderStatus, deliverGoodsStatus);
    }

    public int placeOrder(Integer id){
        return administratorDao.placeOrder(id);
    }

    public List<MaterialListResp> getMaterialList(String orderId,String supplierNo) {
        return administratorDao.getMaterialList(orderId,supplierNo);
    }

    public ShipmentRemarkResp getMaterialDeliverInfo(Integer materialStatusId) {
        return administratorDao.getMaterialDeliverInfo(materialStatusId);
    }

    public List<MaterialManageResp> getMaterialManageInfoList(String materialNo, String materialClass, String supplierId) {
        return administratorDao.getMaterialManageInfoList(materialNo, materialClass, supplierId);
    }

    public int addMaterialInfo(MaterialManageResp materialManageResp){
        return administratorDao.addMaterialInfo(materialManageResp);
    }

    public  MaterialManageResp getMaterialInfoDetail(Integer id){
        return administratorDao.getMaterialInfoDetail(id);
    }

    public int modifyMaterialInfo(MaterialManageResp materialManageResp){
        return administratorDao.modifyMaterialInfo(materialManageResp);
    }

    public int deleteMaterialInfo(Integer id){
        return administratorDao.deleteMaterialInfo(id);
    }

    public List<RewardHistoryResp> getRewardHistoryList(String userName, String rewardStatus) {
        return administratorDao.getRewardHistoryList(userName, rewardStatus);
    }

    public int deleteRewardHistory(Integer id) {
        return administratorDao.deleteRewardHistory(id);
    }

    public int checkConfirm(String orderId) {
        int res1 = administratorDao.checkSupervisionStatus(orderId);
        int res2 = administratorDao.checkManagerStatus(orderId);
        if (res1 > 0 && res2 > 0) {
            return 1;
        } else {
            return 0;
        }
    }

    public List<BillResp> getBillList(String orderId, String identification, String type,String payType) {
        return administratorDao.getBillList(orderId, identification, type,payType);
    }

    public int deleteBillInfo(int id){
        return administratorDao.deleteBillInfo(id);
    }

    public void addBillLog(BillResp billResp){
        administratorDao.addBillLog(billResp);
    }

    public String getPhoneByMaterialId(int id){
        return administratorDao.getPhoneByMaterialId(id);
    }
}
